package com.sc.sc250601.cook.controller;


import com.sc.sc250601.cook.pojo.Comment;
import com.sc.sc250601.cook.pojo.CommentDTO;
import com.sc.sc250601.cook.pojo.Result;
import com.sc.sc250601.cook.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.soap.Text;
import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    CommentService commentService;
    //TODO 实现传递两个参数的Mapper
    @RequestMapping("/selectAllByTidAndType")//根据目标id和类型获取评论
    public Result selectAllByTidAndType(Long targetId,Integer targetType){
        List<Comment> comments=commentService.selectAllByTidAndType(targetId,targetType);
        return new Result(1,"查询评论成功",comments);
    }

    @RequestMapping("/getComment")
    public Result getComments(Integer targetType,Long targetId){
        List<CommentDTO> comments = commentService.getComments(targetType, targetId);
        return new Result(1,"查询评论成功",comments);
    }

    @RequestMapping("/addComment")
    public Result addComment(@RequestBody Comment comment){
        int n=commentService.addComment(comment);
        if(n>0){
            return new Result(1,"新增评论成功");
        }
        return new Result(0,"新增评论失败");
    }
}
